/**
 * 
 */
package com.thor.palmmall.rest.meter.converter;

import java.util.ArrayList;
import java.util.List;

import org.springframework.core.convert.converter.Converter;

import com.thor.palmmall.rest.meter.AMeterInputPeriodValue;
import com.thor.palmmall.rest.order.AOrderActivitie;
import com.thor.palmmall.spi.meter.SMeterInputPeriodValue;
import com.thor.palmmall.spi.order.SOrderActivitie;

/**
 * @author NuoSa
 *
 * @since 1.0
 */
public class AMeterInputPeriodValueConverter
    implements Converter<List<SMeterInputPeriodValue>, List<AMeterInputPeriodValue>> {

  public static AMeterInputPeriodValueConverter getInstance() {
    if (instance == null)
      instance = new AMeterInputPeriodValueConverter();
    return instance;
  }

  private static AMeterInputPeriodValueConverter instance;

  private AMeterInputPeriodValueConverter() {
  }

  @Override
  public List<AMeterInputPeriodValue> convert(List<SMeterInputPeriodValue> sourceList) {
    if(sourceList == null || sourceList.size()==0){
      return null;
    }
    
    List<AMeterInputPeriodValue> targetList = new ArrayList<AMeterInputPeriodValue>();
    for (SMeterInputPeriodValue source : sourceList) {
      AMeterInputPeriodValue target = new AMeterInputPeriodValue();
      target.setLastValue(AMeterValueConverter.getInstance().convert(source.getLastValue()));
      target.setMeterPeriodType(source.getMeterPeriodType());
      target.setMultiply(source.getMultiply());
      target.setValue(source.getValue());
      targetList.add(target);
    }
    return targetList;
  }

}
